<?php

class Member_model extends CI_Model {

    public $id;
    
    
    
    public function getSum($table,$where){
        $query = $this->db->select('id')->where($where)->get($table);
        return count($query->result_array());
    }

    /*
     * 所有用户信息
     * 超级管理 
     */

    public function memberInfo($department_id, $level = 0,$page,$limit) {
        $where = array(
            'department_id' => $department_id,
            'is_verify' => 1
        );
        if ($level == 99) {
            $where = array();
            $where = array(
                'is_verify' => 1
            );
            $query = $this->db->select('su_user.*,su_department.department_name')->where($where)->order_by('level DESC,su_user.id DESC')->join('su_department', 'su_user.department_id=su_department.id', 'left')->limit($limit,$page)->get('su_user');
        } else if ($level == 50) {
            $query = $this->db->select('su_user.*,su_department.department_name')->where($where)->order_by('level DESC,su_user.id DESC')->join('su_department', 'su_user.department_id=su_department.id', 'left')->limit($limit,$page)->get('su_user');
        } else if ($level == 1) {
            $query = $this->db->select('su_user.*,su_department.department_name')->where($where)->order_by('level DESC,su_user.id DESC')->join('su_department', 'su_user.department_id=su_department.id', 'left')->limit($limit,$page)->get('su_user');
        }
        return $query->result_array();
    }

    public function verifyInfo($department_id, $level = 0,$page,$limit) {
        $where = array(
            'is_verify' => 0,
            'department_id' => $department_id,
        );
        if ($level == 99) {
            $query = $this->db->select('su_user.*,su_department.department_name')->where('is_verify=0')->order_by('level DESC,su_user.id DESC')->join('su_department', 'su_user.department_id=su_department.id', 'left')->limit($limit,$page)->get('su_user');
        } else if ($level == 50) {
            $query = $this->db->select('su_user.*,su_department.department_name')->where($where)->order_by('level DESC,su_user.id DESC')->join('su_department', 'su_user.department_id=su_department.id', 'left')->limit($limit,$page)->get('su_user');
        }
        return $query->result_array();
    }

    public function manageInfo($level = 0) {
        $where = array(1,2);
        if ($level == 99) {
            $query = $this->db->select('su_user.*,su_department.department_name')->where_in('is_verify',$where)->where('level<99')->order_by('su_user.id DESC')->join('su_department', 'su_user.department_id=su_department.id', 'left')->get('su_user');
        }
        return $query->result_array();
    }

    public function verifyMember($table, $where, $data) {
        $this->db->where_in('id', $where)->update($table, $data);
        return $this->db->affected_rows() ? true : false;
    }
    public function delMember($table,$where){
        $state = $this->db->where_in('id',$where)->delete($table);
        return $state;
    }

}
